package LeetCode.LeetCode2;

/**
 * 删除链表中的重复节点
 * @author lumin
 * @date 2022/04/04 15:42
 **/
public class Num82 {
    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
    public ListNode deleteDuplicates(ListNode head) {
        ListNode dummyHead = new ListNode(0,head);
        ListNode prev = dummyHead.next;
        while(prev.next != null){
            if(prev.val == prev.next.val){
                prev = prev.next.next;
            }
            prev = prev.next;
        }
        return dummyHead.next;
    }
}